//	Company:	HTHK
//	NAME:	    ProjectOptions.java
//	TITLE:	    The option of Project  in Time Sheet System
//	FUNCTION:	The option of Project associate with the table
//	BY:	        Kodak Xu
//	DATE:	    09/12/2003
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//	CR Log #:  99999  BY:  XXXX   DATE:  dd/mm/yyyy
//	ERROR:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//	FIX:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// --------------------------------------------------------------

//Update By : Beyes Xia
//Update Date:	2004-4-9 11:51

package tss.options;

import tss.common.Options2;

import java.util.ArrayList;
import java.sql.*;

import com.ffpc.sql.*;

import tss.project.*;
import tss.staffproject.*;

public class ProjectOptions extends Options2 {
	public ProjectOptions() {
		this.load();
	}

	@Override
	protected ArrayList createOptions(Connection con) throws Exception {
		ArrayList options = new ArrayList();
		ProjectBean Project = ProjectProcess.createBean();
		Project.setProject_name("");
		ProjectBean[] Projects = ProjectProcess.find(con, Project);
		for (int i = 0; i < Projects.length; i++) {
			Options2.Option option = new Options2.Option(Projects[i].getProject_name(), Projects[i].getProject_name());
			options.add(i, option);
		}
		return options;
	}

	public String getDefualtOptions(String staff, String project) throws Exception {
		StringBuffer htmlOptions = new StringBuffer();
		ConnectionFactory cf = null;
		try {
			cf = new ConnectionFactory("fasp_tss");
			Connection con = cf.getConnection();

			if (project == null || project.length() == 0)
				htmlOptions.append("   <option value=\"\" selected ></option>\n");
			else
				htmlOptions.append("   <option value=\"\" ></option>\n");
			ArrayList options = new ArrayList();
			StaffProjectBean staffProject = StaffProjectProcess.createBean();
			staffProject.setStaff_no(staff);
			StaffProjectBean[] staffProjects = StaffProjectProcess.find(con, staffProject);
			for (int i = 0; i < staffProjects.length; i++) {
				boolean selected = false;
				if (staffProjects[i].getProject_name().equals(project))
					selected = true;
				htmlOptions.append("   <option value=\"").append(staffProjects[i].getProject_name()).append("\"")
						.append(selected ? " selected " : " ").append(" >").append(staffProjects[i].getProject_name())
						.append("</option>\n");
			}
		} catch (Exception e) {
			throw e;
		} finally {
			if (cf != null) {
				cf.finalize();
			}
		}
		return htmlOptions.toString();
	}
}
